package com.flca.frw.validator
{
	import mx.validators.Validator;
	import mx.validators.ValidationResult;
	import mx.validators.StringValidator;
	
	public class PasswordValidator extends StringValidator
	{
		private var results:Array;

		public function PasswordValidator() {
			super();
		}

	    override protected function doValidation(value : Object):Array {
		    // Clear results Array.
		    results = [];
		
		    // Call base class doValidation().
		    results = super.doValidation(value);        
		    if (results.length > 0) {
		        return results;
		    }
		    
		    if (!validateNr(value as String)) {
		        results.push(
		        	new ValidationResult(true, null, "Password", "is niet geldig."));
		        return results;
		    }
		    
		    return results;
		}

		/*
		there must be at least one numeric char
		*/
		private function validateNr(value:String) : Boolean {
			for (var j:int = 0; j < value.length; j++) {
				var c:String = value.charAt(j);
				if (c >= '0' && c <= '9') {
					return true;
				}
			}
			return false;
		}
	}
}